//
//  UIDevice+Extension.swift
//  mall-ios
//
//  Created by Meak Tsui on 2018/11/28.
//  Copyright © 2018 Meak Tsui. All rights reserved.
//

import Foundation
import UIKit

extension UIDevice {
    
    public var modelName:String {
        var systemInfo = utsname()
        uname(&systemInfo)
        
        let platform = withUnsafePointer(to: &systemInfo.machine.0) { ptr in
            return String(cString: ptr)
        }
        
        switch platform {
        case "iPhone1,1":  return "iPhone 2G"
        case "iPhone1,2":  return "iPhone 3G"
        case "iPhone2,1":  return "iPhone 3GS"
        case "iPhone3,1":  return "iPhone 4"
        case "iPhone3,2":  return "iPhone 4"
        case "iPhone3,3":  return "iPhone 4"
        case "iPhone4,1":  return "iPhone 4S"
        case "iPhone5,1":  return "iPhone 5"
        case "iPhone5,2":  return "iPhone 5"
        case "iPhone5,3":  return "iPhone 5C"
        case "iPhone5,4":  return "iPhone 5C"
        case "iPhone6,1":  return "iPhone 5S"
        case "iPhone6,2":  return "iPhone 5S"
        case "iPhone7,1":  return "iPhone 6 Plus"
        case "iPhone7,2":  return "iPhone 6"
        case "iPhone8,1":  return "iPhone 6S"
        case "iPhone8,2":  return "iPhone 6S Plus"
        case "iPhone8,4":  return "iPhone SE"
        case "iPhone9,1":  return "iPhone 7"
        case "iPhone9,2":  return "iPhone 7 Plus"
        case "iPhone10,1":  return "iPhone 8"
        case "iPhone10,2":  return "iPhone 8 Plus"
        case "iPhone10,3":  return "iPhone X"
        case "iPhone10,4":  return "iPhone 8"
        case "iPhone10,5":  return "iPhone 8 Plus"
        case "iPhone10,6":  return "iPhone X"
        case "iPhone11,2": return "iPhone XS"
        case "iPhone11,4": return "iPhone XS Max"
        case "iPhone11,6": return "iPhone XS Max"
        case "iPhone11,8": return "iPhone XR"
        case "iPod1,1":  return "iPod Touch 1G"
        case "iPod2,1":  return "iPod Touch 2G"
        case "iPod3,1":  return "iPod Touch 3G"
        case "iPod4,1":  return "iPod Touch 4G"
        case "iPod5,1":  return "iPod Touch 5G"
        case "iPad1,1":  return "iPad 1"
        case "iPad2,1":  return "iPad 2"
        case "iPad2,2":  return "iPad 2"
        case "iPad2,3":  return "iPad 2"
        case "iPad2,4":  return "iPad 2"
        case "iPad2,5":  return "iPad Mini 1"
        case "iPad2,6":  return "iPad Mini 1"
        case "iPad2,7":  return "iPad Mini 1"
        case "iPad3,1":  return "iPad 3"
        case "iPad3,2":  return "iPad 3"
        case "iPad3,3":  return "iPad 3"
        case "iPad3,4":  return "iPad 4"
        case "iPad3,5":  return "iPad 4"
        case "iPad3,6":  return "iPad 4"
        case "iPad4,1":  return "iPad Air"
        case "iPad4,2":  return "iPad Air"
        case "iPad4,3":  return "iPad Air"
        case "iPad4,4":  return "iPad Mini 2"
        case "iPad4,5":  return "iPad Mini 2"
        case "iPad4,6":  return "iPad Mini 2"
        case "iPad4,7":  return "iPad Mini 3"
        case "iPad4,8":  return "iPad Mini 3"
        case "iPad4,9":  return "iPad Mini 3"
        case "iPad5,1":  return "iPad Mini 4"
        case "iPad5,2":  return "iPad Mini 4"
        case "iPad5,3":  return "iPad Air 2"
        case "iPad5,4":  return "iPad Air 2"
        case "iPad6,3":  return "iPad Pro 9.7"
        case "iPad6,4":  return "iPad Pro 9.7"
        case "iPad6,7":  return "iPad Pro 12.9"
        case "iPad6,8":  return "iPad Pro 12.9"
        default:
            return "unknown"
        }
    }
}
